<?php
/**
 * Object Relational Persistence Mapping Class for table: advice
 *
 * @package	com.athena
 * @author	LHV
 */
class Advice extends ORDataObject {

	/**#@+
	 * Fields of table: advice mapped to class members
	 */
	var $advice_id		= '';
	var $enum_type		= '';
	var $content		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'advice';

	/**
	 * Primary Key
	 */
	var $_key = 'advice_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'Advice';

	/**
	 * Handle instantiation
	 */
	function __construct() {
		parent::ORDataObject();
	}
	/**
	 * Get advice of given enumtype
	 * @param $enumType
	 * <br>
	 * ADVICE_PRESCRIPTION = 'prescription';
     * ADVICE_SURGERY = 'surgery';
	 * @return array()
	 */
	public function getAdviceByType($enumType) {
		$field    =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
        
        $type = 0;
        try {
        	$type = Utils::getEnumKey(EnumerationConstant::ADVICE, $enumType);
        	
        } catch (Exception $ex) {
        	$type = 0;
        }
        
        $ds =& new Datasource_sql();
        $sql = array(
            'cols'  => "t.$field as content",
            'from' => "$this->_table t 
                ",
            'where' => "t.enum_type='$type'",
            'orderby' => 't.advice_id'
            );

        $ds->setup($this->_db,$sql);
        return $ds->toArray();
	} 

	
}
?>
